home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / utils / console / svgatext.3 / svgatext / SVGATextMode-1.3 / contrib / misc / gendac.c
Encoding:
C/C++ Source or Header  |  1995-11-11  |  2.3 KB  |  101 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <unistd.h>
  4. #include "misc.h"
  5. #include "vga_prg.h"
  6. #include "messages.h"
  7. #include "confdefs.h"
  8.  
  9. char *CommandName;
  10. int debug_messages=FALSE;
  11.  
  12. #define NUM_BITS   8
  13. char* int_to_bin(int num, int bits)
  14. {
  15.   static char binstr[sizeof(long int)+1];
  16.   int i;
  17.   
  18.   for (i=0; i<bits; i++) binstr[i] = 0x30; /* char '0' */
  19.   binstr[bits] = 0x00;
  20.   
  21.   for (i=0; i<bits; i++) binstr[bits-1-i] += ((num >> i) & 0x00000001);
  22.   PDEBUG(("binstr = '%s'", binstr));
  23.   return(binstr);
  24. }
  25.  
  26. /***********************************************************************************************************/
  27.  
  28. int main (int argc, char* argv[])
  29. {
  30.   char tempstr[1024]="";
  31.   int program_hardware=TRUE;
  32.   int unlock_chipset=FALSE;
  33.   int pipehex=FALSE;
  34.   int pipe=FALSE;
  35.   int regset = -1;
  36.   char c;
  37.   int tmpbyte=0;
  38.   int regnum=0;
  39.   int setreg = FALSE; /* if TRUE: "getVGAreg" function, if FALSE, "setVGAreg" function */
  40.   char* commandfilename;
  41.   int data=0;
  42.   
  43.  /*
  44.   * See what action is required: read or write VGA register
  45.   */
  46.     
  47.   CommandName = argv[0];
  48.  
  49.  /*
  50.   * command-line argument parsing
  51.   */
  52.  
  53.   while ((c = getopt (argc, argv, "ndhupxt:")) != EOF)
  54.     switch (c)
  55.     {
  56.       case 'n': program_hardware=FALSE;
  57.                 break;
  58.       case 'd': debug_messages=TRUE;
  59.                 break;
  60.       case 'u': unlock_chipset = TRUE;
  61.                 break;
  62.       case 'p': pipe = TRUE;
  63.                 break;
  64.       case 'x': pipehex = TRUE;
  65.                 break;
  66.       default: PERROR(("getopt returned unknown token '%c'.",c));
  67.     }
  68.     
  69. #define GENDAC_INDEX         0x3C8
  70. #define GENDAC_DATA          0x3C9
  71.  
  72.  if (program_hardware)
  73.   {
  74.      unsigned char tmp, tmp1;
  75.      int vgaCRIndex = vgaIOBase + 4;
  76.      int vgaCRReg = vgaIOBase + 5;
  77.  
  78.  
  79.      get_VGA_io_perm(CS_S3);
  80.      if (unlock_chipset) unlock(CS_S3); 
  81.      
  82.      /* set RS2 via CR55, yuck */
  83.      outb(0x55, vgaCRIndex);
  84.      tmp = inb(vgaCRReg) & 0xFC;
  85.      outb(tmp | 0x01, vgaCRReg);
  86.      tmp1 = inb(GENDAC_INDEX);
  87.  
  88.      outb(2, GENDAC_INDEX);
  89.      printf("PLL data regs = 0x%2X, ", inb(GENDAC_DATA));
  90.      printf("0x%2X\n", inb(GENDAC_DATA));
  91.           
  92.      printf("PLL command reg = 0x%2X\n", inb(DAC_MASK));
  93.  
  94.      /* Now clean up our mess */
  95.      outb(tmp1, GENDAC_INDEX);
  96.      outb(tmp, vgaCRReg);
  97.  
  98.   }
  99.   return(0);
  100. }
  101.